import Vue from "vue";
import VueRouter from "vue-router";
import routes from './routes'

//重写编程式导航push|replace方法 -> 解决多次点击报错问题
//调用编程式导航push|replace,this指向务必是VueRouter类的实例
const push = VueRouter.prototype.push;
VueRouter.prototype.push = function(location){
    //call的第一个参数:修改this
    //push(location)-> undefined
    //push.call(this)-> VueRouter类的实例
    push.call(this,location,()=>{},()=>{})
}
const replace = VueRouter.prototype.push;
VueRouter.prototype.replace = function(location){
    replace.apply(this,[location,()=>{},()=>{}])
}

//安装router插件
Vue.use(VueRouter)

export default new VueRouter({
    mode:'hash',
    routes,
    scrollBehavior (to, from, savedPosition) {
        return {
            y:0
        }
    }
})